<%--
  Created by IntelliJ IDEA.
  User: MAX
  Date: 2021-01-25
  Time: 10:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>仓库组织管理</title>
    <base href="<%=request.getContextPath()%>/"/>
    <link rel="stylesheet" href="webjars/layui/2.5.6/css/layui.css">
</head>
<body>

    <fieldset class="layui-elem-field" style="height: 340px">


            <div id="wareHouseTree" style="height: 100%;width:160px;display: inline-block;position: absolute;top: 20px;left: 40px"></div>



        <div style="height: 100%;width:360px;display: inline-block;position: absolute;top: 20px;left: 240px">
                <form class="layui-form" lay-filter="update" style="display: inline-block">

                    <input type="hidden" name="warehousId" class="layui-input" >

                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">仓库名称:</label>
                        <div class="layui-input-inline">
                            <input type="text" name="warehouseName" class="layui-input"  >
                        </div>
                    </div>

                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">仓库编码:</label>
                        <div class="layui-input-inline">
                            <input type="text" name="warehouseCode" class="layui-input" >
                        </div>
                    </div>

                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">仓库级别:</label>
                        <div class="layui-input-inline">
                            <select name="warehouseClass" lay-filter="warehouseClass">
                                <option value="1">一级库</option>
                                <option value="2">二级库</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">所属院区:</label>
                        <div class="layui-input-inline">
                            <input type="text" name="branchCode" class="layui-input" READONLY>
                        </div>
                    </div>

                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">是否可用:</label>
                        <div class="layui-input-inline">
                            <select name="deleteFlag" lay-filter="deleteFlag">
                                <option value="Y">是</option>
                                <option value="N">否</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <div class=" layui-form-item layui-inline" style="margin-left: 160px">
                            <button type="button" onclick="update();" class="layui-btn">提交</button>
                        </div>
                        <div class=" layui-form-item layui-inline">
                            <button type="button" onclick="create();" class="layui-btn"><i class="layui-icon">&#xe654;</i></button>
                        </div>
                    </div>
                </form>
        </div>
    </fieldset>

    <div style="display: none;"  id="create">
        <form class="layui-form" lay-filter="create">
            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">仓库名称:</label>
                <div class="layui-input-inline">
                    <input type="text" name="warehouseName" class="layui-input"  >
                </div>
            </div>

            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">仓库编码:</label>
                <div class="layui-input-inline">
                    <input type="text" name="warehouseCode" class="layui-input" >
                </div>
            </div>

            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">仓库级别:</label>
                <div class="layui-input-inline">
                    <select name="warehouseClass" lay-filter="warehouseClass">
                        <option value="1">一级库</option>
                        <option value="2">二级库</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">所属院区:</label>
                <div class="layui-input-inline">

                    <select name="branchCode" lay-filter="branchCode">
                        <option value="东">东院区</option>
                        <option value="西">西院区</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">是否可用:</label>
                <div class="layui-input-inline">
                    <select name="deleteFlag" lay-filter="deleteFlag">
                        <option value="Y">是</option>
                        <option value="N">否</option>
                    </select>
                </div>
            </div>

        </form>
    </div>


    <script src="webjars/layui/2.5.6/layui.js"></script>
<script>
    function getTree() {
        layui.use(["table", "form", "jquery", 'upload', 'tree', 'layer'], function () {
            let table = layui.table;
            let form = layui.form;
            let $ = layui.$;
            let tree = layui.tree;
            $.post({
                url: 'wareHouse/getTbUscWarehouse',
                dataType: 'json',
                success: function ({data}) {
                    tree.render({
                        id: "wareHouseTree",
                        elem: "#wareHouseTree",
                        data,
                        click: function (obj) {

                            // console.log(obj.data); //得到当前点击的节点数据
                            // console.log(obj.state); //得到当前节点的展开状态：open、close、normal
                            // console.log(obj.elem); //得到当前节点元素
                            // console.log(obj.data.children); //当前节点下是否有子节点
                            if (obj.data.children) {
                                return;
                            }
                            //console.log(obj.data);
                            obj.data.warehouseName = obj.data.title;
                            obj.data.warehousId = obj.data.id;
                            layui.form.val("update", obj.data);

                        }

                    });
                }
            })
        })
    }

    getTree();

    function update() {

        layui.use(["layer","jquery","form"],function () {
            let layer = layui.layer;
            let $ = layui.$;

            let params = layui.form.val("update");
            if(params.warehouseName == "" || params.warehouseName == null){
                return;
            }
            if(params.warehouseCode == "" || params.warehouseCode == null){
                return;
            }
            if(params.branchCode == "" || params.branchCode == null){
                return;
            }
            //console.log(params);


            $.post({
                url:"wareHouse/updateTbUscWarehouse",
                data:JSON.stringify(params),
                contentType:'application/json'})
                .done(({msg})=>{
                    getTree();
                    layer.msg(msg);
                });

            });

    }

    function create() {
        layui.use(["layer", "jquery", "form"], function () {
            let layer = layui.layer;
            let $ = layui.$;

            layer.open({
                type: 1,
                area: ['360px', '400px'],
                skin: 'layui-layer-lan',
                title: '注册信息',
                content: $("#create"),
                btn: ["创建", "返回"],
                yes() {

                    let params = layui.form.val("create");

                    $.post({
                        url: "wareHouse/createTbUscWarehouse",
                        data: JSON.stringify(params),
                        contentType: 'application/json'
                    })
                        .done(({msg}) => {
                            getTree();
                            layer.close(layer.index);
                            layer.msg(msg);
                        });
                    $("#restAdd").click();
                }
            });
        });
    }


</script>
</body>
</html>
